
export default {
  data() {
    return {
      pageLoading: false,
      isScroll: false,
      height: 120,
      status: 'loading',//懒加载
      menberList: [],//成员列表
      getExamine: [],//审核列表
      companyId: '',//公司id
      statuss: '',
      btn: [
        {

        }
      ],
      //懒加载数据
      //成员列表
      menberIndex: 1,//当前页
      //审核列表
      examineIndex: 1,//当前页
      storeId: '',
    }
  },
  onReachBottom(){
    this.getCompanyMemberList()

  },
  onShow(){
    this.menberList = []
    this.menberIndex = 1
    this.$u.throttle(this.getCompanyInfo, 1000)
  },
  created() {

  },
  onLoad(op) {
    const data = uni.getStorageSync('userInfoDetail')

    this.storeId = data.store.storeId

  },
  methods: {
    //我的企业信息
    async getCompanyInfo() {
		  try {
		    let data = {
		      StoreId: this.$store.state.userInfoDetail.store.storeId, //'de39ade6cc0944ac99e1a02cc8f7c729'
		    }
		    const res = await this.$api.company.getCompanyInfo(data)
        this.companyId = res.data.companyId
		    let companyIds = res.data.companyId //存公共方法六里面
		    this.$store.dispatch('getCompanyId', companyIds)

		    this.getCompanyMemberList() // 成员列表
        this.getExamineUserList()
		  } catch (e) {
		    console.log(e)
		  }
    },
    //成员加载更多
    more(){
      // if(this.loadStatus[this.swiperCurrent] !== 'nomore'){
      //   this.buyList()
      // }
      if(this.status!=='nomore'){
        this.getCompanyMemberList()
      }

    },
    //审核加载
    more2(){
      if(this.statuss!=='nomore'){
        this.getExamineUserList()
      }
    },
    //审核下拉加载
    scrolltolower() {
		  this.examineLoad()
    },
    //跳转个人信息
    goInfo(item) {
      let id = JSON.stringify(item)
		  uni.navigateTo({
		    url: '../personalInfo/personalInfo?uid='+id
		  })
    },
    moreStatus(status) {
		  this.status = status
    },
    moreStatus2(status) {
		  this.statuss = status
    },
    // 成员列表
    async getCompanyMemberList() {
      this.status = 'loading'
		  try {

		    let data = {
		      'PageIndex': this.menberIndex,
		      'PageSize': 10,
		      'CompanyId': this.companyId //'f1b343b44a6648c68349d406b62e0c7a'
		    }
		    const res = await this.$api.company.getCompanyMemberList(data)
        if (res.data.total <= 10) {
				  this.status = 'nomore'
        } else {
				  this.moreStatus(res.data.list.length !== 0 ? 'loadmore' : 'nomore')
        }
        this.menberList = [...this.menberList, ...res.data.list]
        // console.log(this.menberList)
        this.pageLoading = true
        if (res.data.list.length === 0) return false
        this.menberIndex += 1 // 当前页加1
		  } catch (e) {

		  }
    },
    //审核列表
    async getExamineUserList() {
      this.statuss = 'loading'
      try {
        let data = {
          'PageIndex': this.examineIndex,
          'PageSize': 10,
          'CompanyId': this.companyId//'f1b343b44a6648c68349d406b62e0c7a'
        }
        const res = await this.$api.company.getExamineUserList(data)
        // console.log(res,'审核')
        this.getExamine = [...this.getExamine, ...res.data.list]
        if(res.data.total<5){
          this.isScroll = false
          this.height = res.data.total*120+50
        }else{
          this.isScroll = true
          this.height = 5*120
        }
        this.pageLoading = true
        if (res.data.total <= 10) {
          this.statuss = 'nomore'
        } else {
          this.moreStatus2(res.data.list.length !== 0 ? 'loadmore' : 'nomore')
        }
        if (res.data.list.length === 0) return false
        this.examineIndex += 1 // 当前页加1
      } catch (e) {
        console.log(e)
      }
    },
    //同意审核
    async updateExamineUserAgree(id){
      try {
			  let data = {
			    'Id': id
			  }
			  const res = await this.$api.company.updateExamineUserAgree(data)

        this.getExamine = []
        this.menberList = []
        this.examineIndex = 1
        this.menberIndex = 1
        this.$u.toast('审核成功')
        this.getExamineUserList()
        this.getCompanyMemberList()
        this.UpdateExamineUserAgreeSMS(id)
      } catch (e) {
			  console.log(e)
      }
    },
    //拒绝审核
    async updateExamineUserRefuse(id){
      try {
			  let data = {
          'Id': id
			  }
			  const res = await this.$api.company.updateExamineUserRefuse(data)

        this.getExamine = []
        this.examineIndex = 1
        this.$u.toast('拒绝成功')
        this.getExamineUserList()
        this.UpdateExamineUserRefuseSNS(id)
      } catch (e) {
			  console.log(e)
      }
    },
    async UpdateExamineUserAgreeSMS(id){
      try {
			  let data = {
			    'id': id
			  }
			  const res = await this.$api.company.UpdateExamineUserAgreeSMS(data)
        console.log(res)
      } catch (e) {
			  console.log(e)
      }
    },
    async UpdateExamineUserRefuseSNS(id){
      try {
			  let data = {
			    'id': id
			  }
			  const res = await this.$api.company.UpdateExamineUserRefuseSNS(data)
        console.log(res)
      } catch (e) {
			  console.log(e)
      }
    },
    // UpdateExamineUserRefuseSNS
    addMenber(){
      // let e = this.companyId
      uni.navigateTo({
        url: '../invite/invite'
      })
    },
    //页面跳转
    goPage(bagName, url) { //bagName 包名 url 页面名称
      uni.navigateTo({
        url: '/' + bagName + '/' + url + '/' + url
      })
    }

  }
}
